package com.heer.gymnasium.module.card.views;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.heer.amap.utils.ToastUtil;
import com.heer.gymnasium.R;
import com.heer.gymnasium.api.ResponseData.ApiResponse;
import com.heer.gymnasium.api.callback.BaseCallback;
import com.heer.gymnasium.base.BaseRefreshActivity;
import com.heer.gymnasium.constant.Type;
import com.heer.gymnasium.module.card.beans.CardResponseBean;
import com.heer.gymnasium.module.card.beans.MyCardBean;
import com.heer.gymnasium.module.card.beans.MyCourseBean;
import com.heer.gymnasium.module.login.views.LoginActivity;
import com.heer.gymnasium.module.main.views.MainActivity;
import com.heer.gymnasium.module.order.views.OrderActivity;
import com.heer.gymnasium.module.reservation.views.TicketDetailActivity;
import com.heer.gymnasium.util.ImageUtil;
import com.heer.gymnasium.util.StringUtils;
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection;
import com.zhihuiyun.library.commonadapter.QuickTypeAdapter;
import com.zhihuiyun.library.commonadapter.ViewHolder;
import com.zhihuiyun.library.view.MyGridView;
import com.zhihuiyun.library.view.MyListView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by yan on 2018/1/18.
 * 我的卡包列表界面
 */

public class MyCardActivity extends BaseRefreshActivity {
    private static final int RES_ID_ROOT_LAYOUT = R.layout.layout_mycard;
    private static final int RES_ID_RECHARGE_RB = R.id.layout_mycard_recharge_rb;
    private static final int RES_ID_MEMBER_RB = R.id.layout_mycard_member_rb;
    private static final int RES_ID_TICKET_RB = R.id.layout_mycard_ticket_rb;
    private static final int RES_ID_COACH_RB = R.id.layout_mycard_coach_rb;
    private static final int RES_ID_COURSE_RB = R.id.layout_mycard_course_rb;

    private static final int RES_ID_RECHARGE_LL = R.id.layout_mycard_recharge_ll;
    private static final int RES_ID_MEMBER_LL = R.id.layout_mycard_member_ll;
    private static final int RES_ID_TICKET_LL = R.id.layout_mycard_ticket_ll;
    private static final int RES_ID_COACH_LL = R.id.layout_mycard_coach_ll;
    private static final int RES_ID_COURSE_LL = R.id.layout_mycard_course_ll;
    private static final int RES_ID_REFRESH = R.id.layout_mycard_srl;
    private static final int RES_ID_LIST_NORMAL_LV = R.id.layout_mycard_lv;
    private static final int RES_ID_OVERDUE_LABLE = R.id.layout_mycard_overdue_label_ll;
    private static final int RES_ID_LIST_OVERDUE_LV = R.id.layout_mycard_overduelist_lv;
    //    adapter布局
    private static final int RES_ID_RECHAGE_ITEM = R.layout.item_mycard_recharge;
    private static final int RES_ID_CARD_ITEM = R.layout.item_admission;

    //   item_mycard_recharge里的ID
    private static final int RES_ID_RECHAGE_ITEM_SOTRENAME = R.id.item_mycard_recharge_storename_tv;
    private static final int RES_ID_RECHAGE_ITEM_MONEY = R.id.item_mycard_recharge_money_tv;
    private static final int RES_ID_RECHAGE_ITEM_RECHARGE = R.id.item_mycard_recharge_recharge_tv;
    //    item_admission里的ID
    private static final int RES_ID_CARD_ITEM_BG = R.id.item_admission_panel_ll;
    private static final int RES_ID_CARD_ITEM_LINE = R.id.item_admission_center_line_v;
    private static final int RES_ID_CARD_ITEM_ICON = R.id.item_admission_iv;
    private static final int RES_ID_CARD_ITEM_NAME = R.id.item_admission_name_tv;
    private static final int RES_ID_CARD_ITEM_TYPE_IV = R.id.item_admission_card_type_iv;
    private static final int RES_ID_CARD_ITEM_TYPE_TV = R.id.item_admission_card_type_tv;
    private static final int RES_ID_CARD_ITEM_ADDRESS = R.id.item_admission_address_tv;
    private static final int RES_ID_CARD_ITEM_ADDRESS_IV = R.id.item_admission_address_iv;
    private static final int RES_ID_CARD_ITEM_TIME = R.id.item_admission_time_tv;
    private static final int RES_ID_CARD_ITEM_TIME_ICON = R.id.item_admission_time_iv;
    private static final int RES_ID_CARD_ITEM_ENTER = R.id.item_admission_enter_iv;

    //    21:会员卡,11:入场券,41:私教课
    private static final int TYPE_MEMEBER = 21;
    private static final int TYPE_COUPON = 11;
    private static final int TYPE_COACH = 41;

    //    0 充值卡，1 会员卡，2 入场券，3 私教卡，4 集体课
    private int type = 0;

    private int cardType = TYPE_MEMEBER;

    private QuickTypeAdapter<CardResponseBean.Item> adapter;
    private List<CardResponseBean.Item> data;

    private QuickTypeAdapter<CardResponseBean.Item> overdueAdapter;

    private List<CardResponseBean.Item> overdueData;
    private Activity $this;

    @BindView(RES_ID_RECHARGE_RB)
    RadioButton rechargeRadioButton;
    @BindView(RES_ID_MEMBER_RB)
    RadioButton memberRadioButton;
    @BindView(RES_ID_TICKET_RB)
    RadioButton ticketRadioButton;
    @BindView(RES_ID_COACH_RB)
    RadioButton coachRadioButton;
    @BindView(RES_ID_COURSE_RB)
    RadioButton courseRadioButton;
    @BindView(RES_ID_LIST_NORMAL_LV)
    MyListView normalListView;
    @BindView(RES_ID_LIST_OVERDUE_LV)
    MyListView overdueListView;
    @BindView(RES_ID_OVERDUE_LABLE)
    LinearLayout labelLinearLayout;

    /**
     * TODO 界面跳转，传参需定义
     *
     * @param context
     */
    public static void startActivity(Context context) {
        Intent intent = new Intent(context, MyCardActivity.class);
        context.startActivity(intent);
    }

    // type 0 充值卡，1 会员卡，2 入场券，3 私教卡，4 集体课
    public static void startActivity(Context context, int type) {
        Intent intent = new Intent(context, MyCardActivity.class);
        intent.putExtra(EXTRA_TYPE, type);
        context.startActivity(intent);
    }

    @Override
    protected void init() {
        super.init();
        $this = this;
        setContentView(RES_ID_ROOT_LAYOUT);
        setRefreshResId(RES_ID_REFRESH);
    }

    @Override
    protected void initView() {
        super.initView();
        titleUtils.setTitleText("我的卡包");
        titleUtils.startMainActivity($this);
        data = new ArrayList<>();
        overdueData = new ArrayList<>();
        type = getIntent().getIntExtra(EXTRA_TYPE, 0);
        setAdapter();
        if (type == 1) {
            cardType = TYPE_MEMEBER;
            labelLinearLayout.setVisibility(View.VISIBLE);
            rechargeRadioButton.setChecked(false);
            memberRadioButton.setChecked(true);
            ticketRadioButton.setChecked(false);
            coachRadioButton.setChecked(false);
            courseRadioButton.setChecked(false);
        } else if (type == 2) {
            cardType = TYPE_COUPON;
            labelLinearLayout.setVisibility(View.VISIBLE);
            rechargeRadioButton.setChecked(false);
            memberRadioButton.setChecked(false);
            ticketRadioButton.setChecked(true);
            coachRadioButton.setChecked(false);
            courseRadioButton.setChecked(false);
        } else if (type == 3) {
            cardType = TYPE_COACH;
            labelLinearLayout.setVisibility(View.VISIBLE);
            rechargeRadioButton.setChecked(false);
            memberRadioButton.setChecked(false);
            ticketRadioButton.setChecked(false);
            coachRadioButton.setChecked(true);
            courseRadioButton.setChecked(false);
        }
    }

    /**
     * 设置适配器
     */
    private void setAdapter() {
        adapter = new QuickTypeAdapter<CardResponseBean.Item>(this, data) {
            @Override
            public void bindData4View(ViewHolder holder, final CardResponseBean.Item data, int adapterType, int pos) {

                switch (type) {
                    case 0:
                        holder.setText(RES_ID_RECHAGE_ITEM_SOTRENAME, data.getStadiumname());
                        holder.setText(RES_ID_RECHAGE_ITEM_MONEY, data.getMoney());
                        holder.getView(RES_ID_RECHAGE_ITEM_RECHARGE).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                OrderActivity.startActivity($this, OrderActivity.OrderType.from_recharge, data.getSid(), Type.ORDER_RECHARGE);
                            }
                        });
                        break;
                    case 1:
                        membershipCardDataFill(holder, data);
                        break;
                    case 2:
                        couponDataFill(holder, data);
                        break;
                    case 3:
                        coachCardDataFill(holder, data);
                        break;
                    case 4:
                        courseDataFill(holder, data);
                        break;
                }

                holder.getParentView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (type != 4 && type != 0) {
                            TicketDetailActivity.startActivity(context, data.getCard_id(), data.getCardType());
                        }
                    }
                });
            }

        };
        overdueAdapter = new QuickTypeAdapter<CardResponseBean.Item>(this, overdueData) {
            @Override
            public void bindData4View(ViewHolder holder, final CardResponseBean.Item data, int adapterType, int pos) {
                switch (type) {
                    case 1:
                        membershipCardDataFill(holder, data);
                        break;
                    case 2:
                        couponDataFill(holder, data);
                        break;
                    case 3:
                        coachCardDataFill(holder, data);
                        break;
                    case 4:
                        courseDataFill(holder, data);
                        break;
                }
                holder.getParentView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (type != 4) {
                            TicketDetailActivity.startActivity(context, data.getCard_id(), data.getCardType());
                        }
                    }
                });
            }
        };
        adapter.addType(0, RES_ID_RECHAGE_ITEM).addType(1, RES_ID_CARD_ITEM);
        normalListView.setAdapter(adapter);
        overdueAdapter.addType(1, RES_ID_CARD_ITEM);
        overdueListView.setAdapter(overdueAdapter);
        if (type == 0) {
            labelLinearLayout.setVisibility(View.GONE);
        } else {
            labelLinearLayout.setVisibility(View.VISIBLE);
        }
    }

    //会员卡
    private void membershipCardDataFill(ViewHolder holder, CardResponseBean.Item data) {
        View bgView = holder.getView(RES_ID_CARD_ITEM_BG);
        View line = holder.getView(RES_ID_CARD_ITEM_LINE);
        TextView name = holder.getView(RES_ID_CARD_ITEM_NAME);
        TextView cardType = holder.getView(RES_ID_CARD_ITEM_TYPE_TV);
        ImageView cardTypeImageView = holder.getView(RES_ID_CARD_ITEM_TYPE_IV);
        TextView address = holder.getView(RES_ID_CARD_ITEM_ADDRESS);
        TextView time = holder.getView(RES_ID_CARD_ITEM_TIME);
        ImageView timeImage = holder.getView(RES_ID_CARD_ITEM_TIME_ICON);
        ImageView enter = holder.getView(RES_ID_CARD_ITEM_ENTER);
        name.setText(data.getShow_name());
        address.setText(data.getStadium_name());
        ImageUtil.loadUrl(this, data.getStadiumpic(), R.drawable.temp_admission, (ImageView) holder.getView(RES_ID_CARD_ITEM_ICON));

        bgView.setBackgroundResource(R.drawable.ticket_yellow_bg);
        line.setBackgroundResource(R.color.black);

        cardTypeImageView.setImageResource(R.drawable.ic_card_gray);
        name.setTextColor(getResources().getColor(R.color.black));

        cardType.setTextColor(getResources().getColor(R.color.black));


        holder.setBg(RES_ID_CARD_ITEM_ADDRESS_IV, R.drawable.ic_location_gray);
        address.setTextColor(getResources().getColor(R.color.black));

        timeImage.setImageResource(R.drawable.ic_time_gray);
        time.setTextColor(getResources().getColor(R.color.black));

        enter.setImageResource(R.drawable.ic_arrow_right);
        holder.setVisibility(RES_ID_CARD_ITEM_TYPE_TV, View.VISIBLE);
        cardType.setText(data.getCard_cat_name());
        time.setText(StringUtils.getPhpDateFormat(data.getEtime(), new SimpleDateFormat("yyyy-MM-dd")) + "\n到期");
    }

    //入场券
    private void couponDataFill(ViewHolder holder, CardResponseBean.Item data) {
        View bgView = holder.getView(RES_ID_CARD_ITEM_BG);
        View line = holder.getView(RES_ID_CARD_ITEM_LINE);
        TextView name = holder.getView(RES_ID_CARD_ITEM_NAME);
        TextView cardType = holder.getView(RES_ID_CARD_ITEM_TYPE_TV);
        ImageView cardTypeImageView = holder.getView(RES_ID_CARD_ITEM_TYPE_IV);
        TextView address = holder.getView(RES_ID_CARD_ITEM_ADDRESS);
        TextView time = holder.getView(RES_ID_CARD_ITEM_TIME);
        ImageView timeImage = holder.getView(RES_ID_CARD_ITEM_TIME_ICON);
        ImageView enter = holder.getView(RES_ID_CARD_ITEM_ENTER);
        name.setText("订场入场券");
        address.setText(data.getStadium_name());
        cardType.setText(data.getCard_cat_name());
        if (data.getStatus().equals("2")) {
            time.setText(StringUtils.getPhpDateFormat(data.getEtime(), new SimpleDateFormat("yyyy/MM/dd")) + "\n已过期");
        } else {
            time.setText(StringUtils.getPhpDateFormat(data.getStime(), new SimpleDateFormat("yyyy/MM/dd"))
                    + "\n" + StringUtils.getPhpDateFormat(data.getStime(), new SimpleDateFormat("HH:ss")) + "-"
                    + StringUtils.getPhpDateFormat(data.getEtime(), new SimpleDateFormat("HH:ss")));
        }
        ImageUtil.loadUrl(this, data.getStadiumpic().replace("\\", "/"), R.drawable.temp_admission, (ImageView) holder.getView(RES_ID_CARD_ITEM_ICON));


        bgView.setBackgroundResource(R.drawable.ticket_black_bg);
        line.setBackgroundResource(R.color.yellow);

        cardTypeImageView.setImageResource(R.drawable.ic_card_white);
        name.setTextColor(getResources().getColor(R.color.white));

        cardType.setTextColor(getResources().getColor(R.color.white));


        holder.setBg(RES_ID_CARD_ITEM_ADDRESS_IV, R.drawable.ic_location_white);
        address.setTextColor(getResources().getColor(R.color.white));

        timeImage.setImageResource(R.drawable.ic_time_white);
        time.setTextColor(getResources().getColor(R.color.white));

        enter.setImageResource(R.drawable.ic_arrow_enter);
    }

    //私教卡
    private void coachCardDataFill(ViewHolder holder, CardResponseBean.Item data) {
        View bgView = holder.getView(RES_ID_CARD_ITEM_BG);
        View line = holder.getView(RES_ID_CARD_ITEM_LINE);
        TextView name = holder.getView(RES_ID_CARD_ITEM_NAME);
        TextView cardType = holder.getView(RES_ID_CARD_ITEM_TYPE_TV);
        ImageView cardTypeImageView = holder.getView(RES_ID_CARD_ITEM_TYPE_IV);
        TextView address = holder.getView(RES_ID_CARD_ITEM_ADDRESS);
        TextView time = holder.getView(RES_ID_CARD_ITEM_TIME);
        ImageView timeImage = holder.getView(RES_ID_CARD_ITEM_TIME_ICON);
        ImageView enter = holder.getView(RES_ID_CARD_ITEM_ENTER);
        name.setText(data.getShow_name());
        address.setText(data.getStadium_name());
        cardType.setText(data.getCard_cat_name());
        if (data.getStatus().equals("2")) {
            time.setText(StringUtils.getPhpDateFormat(data.getEtime(), new SimpleDateFormat("yyyy/MM/dd")) + "\n已过期");
        } else if (data.getEtime() == 0) {
            time.setText("xxxx/xx/xx\n无期限");
        } else {
            time.setText(StringUtils.getPhpDateFormat(data.getStime(), new SimpleDateFormat("yyyy/MM/dd"))
                    + "\n" + StringUtils.getPhpDateFormat(data.getEtime(), new SimpleDateFormat("yyyy/MM/dd")));
        }
        ImageUtil.loadUrl(this, data.getStadiumpic().replace("\\", "/"), R.drawable.temp_admission, (ImageView) holder.getView(RES_ID_CARD_ITEM_ICON));


        bgView.setBackgroundResource(R.drawable.ticket_yellow_bg);
        line.setBackgroundResource(R.color.black);

        cardTypeImageView.setImageResource(R.drawable.ic_card_gray);
        name.setTextColor(getResources().getColor(R.color.black));

        cardType.setTextColor(getResources().getColor(R.color.black));


        holder.setBg(RES_ID_CARD_ITEM_ADDRESS_IV, R.drawable.ic_location_gray);
        address.setTextColor(getResources().getColor(R.color.black));

        timeImage.setImageResource(R.drawable.ic_time_gray);
        time.setTextColor(getResources().getColor(R.color.black));

        enter.setImageResource(R.drawable.ic_arrow_right);
    }

    //集体课
    private void courseDataFill(ViewHolder holder, CardResponseBean.Item data) {
        View bgView = holder.getView(RES_ID_CARD_ITEM_BG);
        View line = holder.getView(RES_ID_CARD_ITEM_LINE);
        TextView name = holder.getView(RES_ID_CARD_ITEM_NAME);
        TextView cardType = holder.getView(RES_ID_CARD_ITEM_TYPE_TV);
        ImageView cardTypeImageView = holder.getView(RES_ID_CARD_ITEM_TYPE_IV);
        TextView address = holder.getView(RES_ID_CARD_ITEM_ADDRESS);
        TextView time = holder.getView(RES_ID_CARD_ITEM_TIME);
        ImageView timeImage = holder.getView(RES_ID_CARD_ITEM_TIME_ICON);
        ImageView enter = holder.getView(RES_ID_CARD_ITEM_ENTER);
        name.setText(data.getCourse_name());
        address.setText(data.getStadiumname());
        cardType.setText("");

        ImageUtil.loadUrl(this, data.getStadiumpic().replace("\\", "/"), R.drawable.temp_admission, (ImageView) holder.getView(RES_ID_CARD_ITEM_ICON));


        bgView.setBackgroundResource(R.drawable.ticket_black_bg);
        line.setBackgroundResource(R.color.yellow);

        cardTypeImageView.setImageResource(R.drawable.ic_card_white);
        name.setTextColor(getResources().getColor(R.color.white));

        cardType.setTextColor(getResources().getColor(R.color.white));


        holder.setBg(RES_ID_CARD_ITEM_ADDRESS_IV, R.drawable.ic_location_white);
        address.setTextColor(getResources().getColor(R.color.white));

        timeImage.setImageResource(R.drawable.ic_time_white);
        time.setTextColor(getResources().getColor(R.color.white));

        enter.setImageResource(R.drawable.ic_arrow_enter);

        String startTime = StringUtils.getPhpDateFormat(data.getStart_time(), new SimpleDateFormat("yyyy-MM-dd HH:ss"));
        String endTime = StringUtils.getPhpDateFormat(data.getEnd_time(), new SimpleDateFormat("yyyy-MM-dd HH:ss"));
        if (StringUtils.currentTimeIsOverdue(data.getEnd_time())) {
            endTime = "已过期";
        } else {
            endTime = startTime.substring(startTime.lastIndexOf(":") - 2, startTime.length()) + "-"
                    + endTime.substring(endTime.lastIndexOf(":") - 2, endTime.length());
        }
        time.setText(startTime.substring(0, startTime.lastIndexOf(" ")) + "\n" + endTime);
    }


    @Override
    protected void loadData(boolean loadMore) {
        super.loadData(loadMore);
        if (type == 0) {
            getMyRechargeCardList();
        } else if (type == 4) {
            getCourseList();
        } else {
            getMyCardData();
        }

        if (layoutRefresh.isRefreshing()) {
            layoutRefresh.setRefreshing(false);
        }
    }


    @OnClick({RES_ID_RECHARGE_LL, RES_ID_MEMBER_LL, RES_ID_TICKET_LL, RES_ID_COACH_LL, RES_ID_COURSE_LL})
    public void onCheckedChanged(View view) {
        pageNo = 1;
        switch (view.getId()) {
            case RES_ID_RECHARGE_LL:
                labelLinearLayout.setVisibility(View.GONE);
                rechargeRadioButton.setChecked(true);
                memberRadioButton.setChecked(false);
                ticketRadioButton.setChecked(false);
                coachRadioButton.setChecked(false);
                courseRadioButton.setChecked(false);
                type = 0;
                getMyRechargeCardList();
                break;
            case RES_ID_MEMBER_LL:
                labelLinearLayout.setVisibility(View.VISIBLE);
                rechargeRadioButton.setChecked(false);
                memberRadioButton.setChecked(true);
                ticketRadioButton.setChecked(false);
                coachRadioButton.setChecked(false);
                courseRadioButton.setChecked(false);
                type = 1;
                cardType = TYPE_MEMEBER;
                getMyCardData();
                break;
            case RES_ID_TICKET_LL:
                labelLinearLayout.setVisibility(View.VISIBLE);
                rechargeRadioButton.setChecked(false);
                memberRadioButton.setChecked(false);
                ticketRadioButton.setChecked(true);
                coachRadioButton.setChecked(false);
                courseRadioButton.setChecked(false);
                type = 2;
                cardType = TYPE_COUPON;
                getMyCardData();
                break;
            case RES_ID_COACH_LL:
                labelLinearLayout.setVisibility(View.VISIBLE);
                rechargeRadioButton.setChecked(false);
                memberRadioButton.setChecked(false);
                ticketRadioButton.setChecked(false);
                coachRadioButton.setChecked(true);
                courseRadioButton.setChecked(false);
                type = 3;
                cardType = TYPE_COACH;
                getMyCardData();
                break;
            case RES_ID_COURSE_LL:
                labelLinearLayout.setVisibility(View.VISIBLE);
                rechargeRadioButton.setChecked(false);
                memberRadioButton.setChecked(false);
                ticketRadioButton.setChecked(false);
                coachRadioButton.setChecked(false);
                courseRadioButton.setChecked(true);
                type = 4;
                getCourseList();
                break;
            default:
                break;
        }
    }

    //   获取我的卡包数据
    public void getMyCardData() {
        mAppHelper.apiService().getMyCardList(cardType + "").enqueue(new BaseCallback<ApiResponse<CardResponseBean>>() {

            @Override
            public void onSuccess(Call<ApiResponse<CardResponseBean>> call, Response<ApiResponse<CardResponseBean>> response) {
                dataParse(response);

            }

            @Override
            public void onError(Call<ApiResponse<CardResponseBean>> call, Throwable t) {
                super.onError(call, t);
                data.clear();
                overdueData.clear();
                adapter.notifyDataSetChanged();
                overdueAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(Call<ApiResponse<CardResponseBean>> call, Throwable t) {
                super.onFailure(call, t);
                data.clear();
                overdueData.clear();
                adapter.notifyDataSetChanged();
                overdueAdapter.notifyDataSetChanged();
            }
        });

    }

    //获取集体课数据
    public void getCourseList() {
        mAppHelper.apiService().myCourseList(pageNo + "").enqueue(new BaseCallback<ApiResponse<CardResponseBean>>() {

            @Override
            public void onSuccess(Call<ApiResponse<CardResponseBean>> call, Response<ApiResponse<CardResponseBean>> response) {
                dataParse(response);
            }
        });

    }

    //获得充值卡数据
    public void getMyRechargeCardList() {
        mAppHelper.apiService().getMyRechargeCardList(pageNo + "").enqueue(new BaseCallback<ApiResponse<CardResponseBean>>() {

            @Override
            public void onSuccess(Call<ApiResponse<CardResponseBean>> call, Response<ApiResponse<CardResponseBean>> response) {
                dataParse(response);
            }
        });
    }

    //请求数据公共解析部分
    private void dataParse(Response<ApiResponse<CardResponseBean>> response) {
        if (pageNo == 1) {
            data.clear();
            overdueData.clear();
        }
        int total = StringUtils.toInt(response.body().getData().getTotal());
        int current = StringUtils.toInt(response.body().getData().getCurrent_page());
        int per_page = StringUtils.toInt(response.body().getData().getPer_page());
        if (total <= current * per_page) {
            layoutRefresh.setDirection(SwipyRefreshLayoutDirection.TOP);
        }
        CardResponseBean bean = response.body().getData();
        for (int i = 0; i < bean.getData().size(); i++) {
            CardResponseBean.Item item = bean.getData().get(i);
            if (type == 0) {
                item.setQuickType(0);
                data.add(item);
            } else {
                item.setQuickType(1);
                if (type == 4) {
                    Date endTime = new Date(item.getEnd_time() * 1000);
                    Date currentTime = new Date(System.currentTimeMillis());
                    if (endTime.after(currentTime)) {
                        data.add(item);
                    } else {
                        overdueData.add(item);
                    }
                } else {
                    if (item.getStatus().equals("1")) {
                        data.add(item);
                    } else {
                        overdueData.add(item);
                    }
                }
            }
        }
        adapter.notifyDataSetChanged();
        overdueAdapter.notifyDataSetChanged();

    }
}
